package com.yilife.hmstr.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yilife.hmstr.domain.MeridianAnalysis;
import com.yilife.hmstr.domain.ma;
import com.yilife.hmstr.mapper.MeridianAnalysisMapper;
import com.yilife.hmstr.service.MeridianAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 经络表业务实现类
 */

@Service
public class MeridianAnalysisServiceImpl implements MeridianAnalysisService {
	
	@Autowired
	private MeridianAnalysisMapper meridianAnalysisMapper;

	/**
	 * 添加数据
	 * @param ma
	 */
	public void add(MeridianAnalysis ma){
//		if(ma!=null||meridianAnalysisMapper.selectById(ma.getHmstrId())==null){
//			meridianAnalysisMapper.insert(ma);
//		}else{
//			meridianAnalysisMapper.updateById(ma);
//		}
		if(ma!=null&&selectByPid(ma.getHmstrId()).getMeridianAnalysis().size()==0){
			meridianAnalysisMapper.insert(ma);
		}
	}

	/**
	 * 根据主键删除数据
	 * @param id
	 */
	public void del(long id){
		meridianAnalysisMapper.deleteById(id);
	}

	/**
	 * 根据外键删除数据
	 * @param id
	 */
	public void delByPid(long id){
		meridianAnalysisMapper.delete(new EntityWrapper<MeridianAnalysis>().eq("hmstr_id", id));
	}

	/**
	 * 根据主键查询数据
	 * @param id
	 * @return
	 */
	public String selectById(long id){
		return meridianAnalysisMapper.selectById(id).toString();
	}
	
	/*
	public String selectByPid(int pid){
		String string="";
		List<MeridianAnalysis> mas=meridianAnalysisMapper.selectList(new EntityWrapper<MeridianAnalysis>().eq("hmstr_id", pid));
		for (MeridianAnalysis fiveElementsReport : mas) {
			string=string+"\n\n"+fiveElementsReport.toString();
		}
		return string;
	}
	*/

	/**
	 * 根据外键查询数据
	 * @param pid
	 * @return
	 */
	public ma selectByPid(long pid){
		List<MeridianAnalysis> mas=meridianAnalysisMapper.selectList(new EntityWrapper<MeridianAnalysis>().eq("hmstr_id", pid));
		return new ma(mas);
	}
	
	public void update(){
		
	}
	
}
